﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebStudio.Business.Entity;
using WebStudio.Business.Rule;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadData();
        }
    }

    private void loadData()
    {
        rptBind(rptNewsLatest);
        rptBind(rptProduct);
        rptBind(rptCase);
        rptBind(rptMessage);
        rptBind(rptFlink);
        rptBind(rptParent);
    }

    private void rptBind(Repeater rpt)
    {
        if (rpt.Equals(rptNewsLatest))
        {
            rpt.DataSource = ArticalRule.GetArticalList(7, 1);
        }
        if (rpt.Equals(rptProduct))
        {
            rpt.DataSource = PhotoRule.GetPhotoList(6);
        }
        if (rpt.Equals(rptCase))
        {
            rpt.DataSource = ArticalRule.GetArticalList(5, 3);
        }
        if (rpt.Equals(rptMessage))
        {
            rpt.DataSource = MessageRule.GetMessageList(9, "Status=1");
        }
        if (rpt.Equals(rptFlink))
        {
            rpt.DataSource = FriendUrlRule.GetFriendUrlList(1);//1代表显示，0代表隐藏
        }
        if (rpt.Equals(rptParent))
        {
            rpt.DataSource = AlbumRule.GetParentAlbumlList(0);
        }
        rpt.DataBind();
    }

    protected void rptParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField hfCId = (HiddenField)e.Item.FindControl("hfCId");
            Repeater rptSub = (Repeater)e.Item.FindControl("rptSub");
            int cid = Convert.ToInt32(hfCId.Value);
            rptSub.DataSource = AlbumRule.GetParentAlbumlList(cid);
            rptSub.DataBind();
        }
    }
}
